<template>
  <div>
    <el-aside width="86%" class="aside">
      <el-menu :default-openeds="defaultOpeneds"  @select="handleSelect">
        <el-submenu :index="item.code" v-for="item in menuList" :key="item.code">
          <template slot="title"><i class="el-icon-menu"></i>{{item.name}}</template>
          <el-menu-item :index="sub.code" v-for="sub in item.children">{{sub.name}}</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
  </div>
</template>

<script>
  import data from '../settings/data'
  export default {
    name: "Aside",
    props: {
      menuList: {
        type: Array,
        required: false,
        default: function () {
          return data.menu
        }
      },
      defaultOpeneds: {
        type: Array,
        required: false,
        default: function () {
          return ['1']
        }
      }
    },
    data () {
      return {
        list: data.menu
      }
    },
    methods: {
      handleSelect(index, path){
        if(path.length > 1){
          let [ind] = path;
          let item = this.menuList.filter(val => val.code === ind)[0];
          let child = item.children.filter(val => val.code === index)[0];
          this.$router.push(child.path);
        }
      }
    },
    mounted () {
      let _this = this
      const list = _this.list
      if(sessionStorage.getItem('_consumer_info_')=='超级管理员'){
        return _this.menuList = list
      }else{
        this.menuList[0].children.splice(1,2)
        return _this.menuList
      }
    }
  }
</script>

<style scoped>

</style>
